#!/bin/bash
#chkconfig:2345 20 90
#description:kafka
#processname:kafka

source ~/.bashrc
JAVA_HOME={{ jdk_home }}
KAFKA_HOME={{ kafka_basedir }}
PATH=$JAVA_HOME/bin:$PATH 

case $1 in
	start) 
	   ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties
	   ;;

	stop)
	   ${KAFKA_HOME}/bin/kafka-server-stop.sh
	   ;;

	status)
           k_pid=`ps -ef | grep kafkaServer | grep -v grep | awk '{print $2}'`
           if [ "$k_pid" = "" ] ; then
               echo "Stopped"
               exit 3
           else
               echo "Running $k_pid"
               exit 0
           fi
	   ;;

	restart)
	   ${KAFKA_HOME}/bin/kafka-server-stop.sh
	   ${KAFKA_HOME}/bin/kafka-server-start.sh -daemon ${KAFKA_HOME}/config/server.properties
	   ;;

	*)
	   echo "require start|stop|status|restart"
	   ;;
esac

